FROM daocloud.io/php:7.2-fpm-alpine
# FROM centos/php-72-centos7
ENV XHPROF_VERSION 2.0.5



###########################################################################
# MongoDB:
###########################################################################

# ARG INSTALL_MONGO=true



RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && apk add --no-cache --virtual .build-deps \
        $PHPIZE_DEPS \
        curl-dev \
        imagemagick-dev \
        libtool \
        libxml2-dev \
        postgresql-dev \
        sqlite-dev \
        graphviz\
        autoconf \
    && apk add --no-cache \
        curl \
        git \
        imagemagick \
        mysql-client \
        postgresql-libs \
    && docker-php-ext-install \
        curl \
        iconv \
        mbstring \
        pdo \
        pdo_mysql \
        pdo_pgsql \
        pdo_sqlite \
        pcntl \
        tokenizer \
        xml \
        zip \
        bcmath 
  
    # && curl -s https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin/ --filename=composer \
    # && apk del -f .build-deps\
    # && composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/ \ 
    # 设置时间  
   # && /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
   # && echo 'Asia/Shanghai' > /etc/timezone

# XHPROF 安装 ； 
  # RUN  wget https://github.com/longxinH/xhprof/archive/v${XHPROF_VERSION}.tar.gz -O /tmp/xhprof.tar.gz \
  #       && mkdir -p /tmp/xhprof \
  #       && tar -xf /tmp/xhprof.tar.gz -C /tmp/xhprof --strip-components=1 \
  #       && rm /tmp/xhprof.tar.gz \
  #       && ( \
  #       cd /tmp/xhprof/extension \
  #       && phpize \
  #       && ./configure \
  #       && make -j$(nproc) \
  #       && make install \
  #       ) \
  #       && rm -r /tmp/xhprof \
  #       && docker-php-ext-enable xhprof


#Swoole 扩展安装 开启扩展
  # RUN  wget https://github.com/longxinH/xhprof/archive/v${XHPROF_VERSION}.tar.gz -O /tmp/xhprof.tar.gz \
  #       && mkdir -p /tmp/xhprof \
  #       && tar -xf /tmp/xhprof.tar.gz -C /tmp/xhprof --strip-components=1 \
  #       && rm /tmp/xhprof.tar.gz \
  #       && ( \
  #       cd /tmp/xhprof/extension \
  #       && phpize \
  #       && ./configure \
  #       && make -j$(nproc) \
  #       && make install \
  #       ) \
  #       && rm -r /tmp/xhprof \
  #       && docker-php-ext-enable xhprof
        

# 修改 composer 为国内镜像


#Mongodb 扩展安装 开启扩展
# RUN wget https://house-sell.oss-cn-chengdu.aliyuncs.com/mongodb-1.9.0.tgz -O /tmp/mongodb-1.9.0.tgz \

# RUN wget https://pecl.php.net/get/mongodb-1.9.0.tgz -O /tmp/mongodb-1.9.0.tgz \
RUN wget http://download.l.dongdongidea.com/mongodb-1.9.0.tgz -O /tmp/mongodb.tar.gz \
 && mkdir -p /tmp/mongodb \
 && tar -xf /tmp/mongodb.tar.gz -C /tmp/mongodb --strip-components=1 \
 && rm /tmp/mongodb.tar.gz \
 && ( \
 cd /tmp/mongodb \
 && phpize \
 && ./configure --enable-async-redis --enable-mysqlnd --enable-openssl --enable-http2 \
 && make -j$(nproc) \
 && make install \
 ) \
 && rm -r /tmp/mongodb \
 && docker-php-ext-enable mongodb


#  && pecl install xdebug-2.6.1 \
#   pecl install imagick \ 获取失败；； 
#  && docker-php-ext-enable xdebug \


#    && pecl install imagick \
#    && docker-php-ext-enable imagick \


# RUN pecl install https://house-sell.oss-cn-chengdu.aliyuncs.com/mongodb-1.9.0.tgz && docker-php-ext-enable mongodb  


###########################################################################
# Xhprof:
###########################################################################

ARG INSTALL_XHPROF=true

RUN if [ ${INSTALL_XHPROF} = true ]; then \
    # Install the php xhprof extension
    if [ $(php -r "echo PHP_MAJOR_VERSION;") = 7 ]; then \
      curl -L -o /tmp/xhprof.tar.gz "https://github.com/tideways/php-xhprof-extension/archive/v5.0.1.tar.gz"; \
    else \ 
      curl -L -o /tmp/xhprof.tar.gz "https://codeload.github.com/phacility/xhprof/tar.gz/master"; \
    fi \
    && mkdir -p xhprof \
    && tar -C xhprof -zxvf /tmp/xhprof.tar.gz --strip 1 \
    && ( \
        cd xhprof \
        && phpize \
        && ./configure \
        && make \
        && make install \
    ) \
    && rm -r xhprof \
    && rm /tmp/xhprof.tar.gz \
;fi

COPY ./xhprof.ini /usr/local/etc/php/conf.d

RUN if [ ${INSTALL_XHPROF} = false ]; then \
    rm /usr/local/etc/php/conf.d/xhprof.ini \
;fi




# RUN  wget --no-check-certificate https://github.com/tideways/php-xhprof-extension/archive/v4.1.7.tar.gz \
#   && tar zxvf v4.1.7.tar.gz \
#   && cd php-xhprof-extension-4.1.7 \
#   && phpize && ./configure && make \
#   && make install \
#   &&  COPY ./xhprof.ini /usr/local/etc/php/conf.d  